package cn.zch.controller;
import cn.zch.utils.diplomacy.acrel.wsdl.AcrelManageLocator;
import cn.zch.utils.diplomacy.acrel.wsdl.AcrelManageSoap_BindingStub;
import cn.zch.utils.diplomacy.acrel.wsdl.GetMeterInfoSuSheResponseGetMeterInfoSuSheResult;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
@Controller
@Slf4j
@RequestMapping("test/acrel")
public class AcrelTestController {
  @ResponseBody
  @RequestMapping(value = "/GetMeterInfoSuShe")
  public String test14AcrelManageSoapGetMeterInfoSuShe(HttpServletRequest request, HttpServletResponse response) throws Exception {
    if (StringUtils.isEmpty(request) || StringUtils.isEmpty(request.getParameterMap()) || request.getParameterMap().isEmpty()) {
      return "输入为空";
    }
    AcrelManageSoap_BindingStub binding;
    try {
      binding = (AcrelManageSoap_BindingStub) new AcrelManageLocator().getAcrelManageSoap();
    }
    catch (javax.xml.rpc.ServiceException jre) {
      if (jre.getLinkedCause() != null)
        jre.getLinkedCause().printStackTrace();
      throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
    }
    System.out.println("binding = " + binding);
    log.info("binding = " + binding);
    // Time out after a minute
    binding.setTimeout(60000);
    // Test operation
    GetMeterInfoSuSheResponseGetMeterInfoSuSheResult value;
    value = binding.getMeterInfoSuShe("T1304");
    return JSON.toJSONString(value);
    // TBD - validate results
  }
}
